<template>
	<view class="ys">
		<y-header></y-header>
		<view class="userbody">
			<y-bread :name="pageName"></y-bread>
			<view class="usermain">
				<view class="left">
					<y-usermenu></y-usermenu>
				</view>
				<view class="right">
					<view class="orderlist-title">
						<text>{{pageName}}</text>
					</view>
					<view class="add-content" v-show="!showAddress">
						<button @click="addRecipient">{{$t('index.xzsjr')}}</button>
					</view>
					<view class="addbody" v-if="showAddress">
						<y-address @cancle="cancle" :item="item" @sure="sure"></y-address>
					</view>
					<view class="addlist" v-show="!showAddress">
						<view class="additem" v-for="(item,index) in addList" :key="index">
							<view class="addleft">
								<view class="name">
									{{item.name}}
								</view>
								<view class="phone">
									{{item.phone}}
								</view>
								<view class="content">
									{{item.address}}
								</view>
							</view>
							<view class="addright">
								<view class="">
									<uni-icons :size="17" color="#999" type="closeempty"></uni-icons>
								</view>
								<view class="">
									<text class="edit" @click="editItem(item)">{{$t('index.bj')}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		UserAddressList
	} from "@/api/user.js"
	export default {
		data() {
			return {
				pageName: this.$t('index.cysjr'),
				showAddress: false,
				addList: [],
				item: ''
			}
		},
		onLoad() {
			this.UserAddressList()
		},
		methods: {
			UserAddressList() {
				UserAddressList().then(res => {
					this.addList = res.data
				})
			},
			addRecipient() {
				this.showAddress = true
				this.pageName = this.$t('index.xzsjr')
			},
			cancle() {
				this.showAddress = false
				this.pageName = this.$t('index.cysjr')
			},
			sure(e) {
				this.showAddress = false
				this.pageName = this.$t('index.cysjr')
				let i = this.addList.findIndex(item => item.id == e.id)
				if (i >= 0) {
					this.addList[i] = e
				} else {
					this.addList.push(e)
				}
			},
			editItem(item) {
				this.item = item
				this.showAddress = true
				this.pageName = this.$t('index.bjcysjr')
			}
		}
	}
</script>

<style lang="scss">
	.userbody {
		max-width: 1180px;
		margin: 0 auto;
		margin-top: 20px;
		padding: 10px;
		box-sizing: border-box;
	}

	.additem {
		border: 1px solid #ddd;
		margin-bottom: 10px;
		border-radius: 5px;
		padding: 12px 15px;
		display: flex;
		justify-content: space-between;

		.addleft {
			font-size: 15px;
			color: #333333;
			word-break: break-all;
			line-height: 20px;

			.phone {
				margin-top: 5px;
				font-size: 13px;
				color: #333333;
				word-break: break-all;
				line-height: 19px;
			}

			.content {
				margin-top: 5px;
				color: #666666;
				font-size: 13px;
				word-break: break-all;
				line-height: 19px;
			}
		}

		.addright {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			font-size: 14px;
			color: #469be5;
			align-items: flex-end;

			.edit {
				cursor: pointer;
			}
		}
	}

	.usermain {
		display: flex;
		justify-content: space-between;

		.left {
			box-sizing: border-box;
			width: 25%;
			max-width: 265px;
			margin-top: 20px;
			margin-bottom: 20px;
		}

		.right {
			box-sizing: border-box;
			width: 75%;
			padding-right: 1%;
			margin-top: 20px;
			margin-bottom: 20px;

			.orderlist {
				margin-top: 15px;
			}

			.orderlist-title {
				font-size: 22px;
				border-left: 3px solid #4a4e5c;
				padding-left: 7px;
			}

			.add-content {
				margin: 30px 0px 20px;

				button {
					border-radius: 4.5px;
					font-size: 14px;
					text-align: center;
					box-sizing: border-box;
					display: inline-block;
					background-color: #ff5353;
					color: #fff;
					cursor: pointer;
					border: 1px solid #ff5353;
					height: 40px;
					line-height: 40px;
					padding: 0px 20px;
					width: auto;
					min-width: 200px;
				}
			}
		}
	}

	@media (max-width:768px) {
		.usermain {
			.left {
				display: none;
			}

			.right {
				width: 100%;
				padding: 0;

				.orderitem .goodsinfo {
					.imgbox {
						width: 80px;
						height: 80px;
					}

					.goodsname {
						.name {
							-webkit-line-clamp: 2;
						}

						.goods-status {
							font-size: 12px;
							margin: 5px 0;
						}
					}
				}

			}
		}

		.pc {
			display: none;
		}
	}
</style>